<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<HTML XMLNS="http://www.w3.org/1999/xhtml">
<HEAD>
<%
if request.Cookies("Hsuser")="" then
	%>
	<script type="text/javascript" language="javascript">
	parent.window.location.href="LoginScreen.asp"
	</SCRIPT>
	<%
end if

%>

<script type="text/javascript" language="javascript">
function OpenAcct(contract_id)
{
	parent.location.href="ApplicationFrameSet.asp?ContractID=" + contract_id;
}
</SCRIPT>

<TITLE>Search Results</TITLE>
<LINK HREF="UniversalStyleSheet.css" REL="stylesheet" TYPE="text/css" />

<STYLE TYPE="text/css">
<!--
body {
	margin-left: 0px;
	margin-top: 0px;
	margin-right: 0px;
	margin-bottom: 0px;
}
-->
</STYLE><META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1" /></HEAD>

<BODY>
<% 
'build query
if request.Form("SearchWhat")<>"" then

Dim rs,rs2
dim db,db2
Select Case request.Form("SearchWhat")
	case "Account"
		AccountNumber=request.Form("AccountNumber")
		if IsNumeric(AccountNumber) then
			AccountNumber=Clng(AccountNumber)
		else
			AccountNumber=1
		end if
		sql="Select First_Name,Last_Name,address, Contract_ID from customers where Account_Number=" & AccountNumber
		
		set db=Server.CreateObject("adodb.connection")
		set rs=Server.CreateObject("adodb.recordset")
		
		FilePath=server.MapPath("/afterhours/access/backend/homesmart_customers.mdb")

		db.open ("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & FilePath)
		
		rs.open sql,db,1,2
				
		if rs.recordcount=0 then 
			set1="nothing"
			set2="nothing"
			ra1row=0
			rscount=0
			rs.close
			set rs=nothing
		else
			set1="something"
			set2="something"
			rscount=rs.recordcount
			ra1=rs.getrows()
			ra1row=ubound(ra1,2)
			redim ra3(4,rscount)
			rs.close
			set rs=nothing
		end if

		x=0
		if set1<>"nothing" then
			do until x>ra1row
				ra3(0,x)=ra1(0,x)
				ra3(1,x)=ra1(1,x)
				ra3(2,X)=ra1(2,x)
				ra3(3,x)=ra1(3,x)
				x=x+1
				response.Write(ra3(0,x) & "<BR/>")
			loop
		end if

		rcnt=x-1
		if rcnt<0 then rcnt=0
		x=0
		db.close
		set db=nothing
				
	case "NameAddress"
		if request.Form("firstname")="" then
			firstname=""
		else
			firstname=request.Form("firstname")
		end if
		
		if request.form("lastname")="" then
			lastname=""
		else
			lastname=request.Form("lastname")
		end if
		
		if request.form("address")="" then
			address=""
		else
			address=request.Form("address")
		end if
		
		sql1="Select First_Name,Last_Name,address, Contract_ID from non_homeSmart_customers where First_Name like '%" & firstname & "%' and Last_Name like '%" & lastname & "%' and Address like '%" & address & "%';"
		sql2="Select First_Name,Last_Name,address, Contract_ID from customers where First_Name like '%" & firstname & "%' and Last_Name like '%" & lastname & "%' and Address like '%" & address & "%';"
		
		set db=Server.CreateObject("adodb.connection")
		set db2=server.CreateObject("adodb.connection")
		set rs=Server.CreateObject("adodb.recordset")
		set rs2=server.CreateObject("adodb.recordset")

		FilePath=server.MapPath("/afterhours/access/backend/tickets.mdb")
		FilePath2=server.MapPath("/afterhours/access/backend/homesmart_customers.mdb")

		db.open ("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & FilePath)
		db2.open ("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & FilePath2)

		rs.open sql1,db,1,2
		rs2.open sql2,db2,1,2
		
		if rs.eof then 
			set1="nothing"
			ra1row=0
			rscount=0
			rs.close
			set rs=nothing
		else
			set1="something"
			rscount=rs.recordcount
			ra1=rs.getrows()
			ra1row=ubound(ra1,2)
			redim ra3(4,rscount)
			rs.close
			set rs=nothing
		end if

		if rs2.eof then 
			set2="nothing"
			ra2row=0
			rs2count=0
			rs2.close
			set rs2=nothing
		else
			set2="something"
			rs2count=rs2.recordcount
			ra2=rs2.getrows()
			ra2row=ubound(ra2,2)
			redim ra3(4,rscount + rs2count)
			rs2.close
			set rs2=nothing
		end if

		x=0
		if set1<>"nothing" then
			do until x>ra1row
				ra3(0,x)=ra1(0,x)
				ra3(1,x)=ra1(1,x)
				ra3(2,X)=ra1(2,x)
				ra3(3,x)=ra1(3,x)
				x=x+1
			loop
		end if

		y=0
		if set2<>"nothing" then
			do until y> ra2row
				ra3(0,x)=ra2(0,y)
				ra3(1,x)=ra2(1,y)
				ra3(2,x)=ra2(2,y)
				ra3(3,x)=ra2(3,y)
				x=x+1
				y=y+1
			loop
		end if
		rcnt=x-1
		if rcnt<0 then rcnt=0
		x=0
		db.close
		db2.close
		set db=nothing
		set db2=nothing
					
	case "Ticket"
		TicketNumber=request.Form("TicketNumber")
		if IsNumeric(TicketNumber) then
			TicketNumber=Clng(TicketNumber)
		else
			TicketNumber=0
		end if
		sql="select Contract_ID from Tickets where Ticket_ID=" & TicketNumber
		
		set db=Server.CreateObject("adodb.connection")
		set db2=server.CreateObject("adodb.connection")
		set rs=Server.CreateObject("adodb.recordset")
		set rs2=server.CreateObject("adodb.recordset")

		FilePath=server.MapPath("/afterhours/access/backend/tickets.mdb")
		FilePath2=server.MapPath("/afterhours/access/backend/homesmart_customers.mdb")

		db.open ("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & FilePath)
		db2.open ("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & FilePath2)

		rs.open sql,db,1,2
		if rs.eof then
			ContractID=0
			set1="nothing"
			set2="nothing"
			rcnt=0
			rs.close
			set rs=nothing
		else
			set1="something"
			set2="something"
			ra=rs.getrows()
			ContractID=ra(0,0)
			if isnumeric(left(contractid,1)) then
				sql2="select first_name, last_name, address from customers where Contract_ID='" & contractID & "'"
				rs2.open sql2,db2,1,2
			else
				sql2="select first_name, last_name, address from non_homesmart_customers where contract_id='" & contractid & "'"
				rs2.open sql2,db,1,2
			end if
			
			ra2=rs2.getrows()
			redim ra3(4,1)
			ra3(0,0)=ra2(0,0)
			ra3(1,0)=ra2(1,0)
			ra3(2,0)=ra2(2,0)
			ra3(3,0)=contractID
			rcnt=0
			rs2.close
			set rs2=nothing
			db.close
			db2.close
			set db=nothing
			set db2=nothing
		end if
	end select


end if 'for if searchwhat <>""
if request.Form("SearchWhat")="" then
	rcnt=0
	x=0
	set1=""
	set2=""
end if
%>

<TABLE WIDTH="300" BORDER="0" ALIGN="left" CELLPADDING="0" CELLSPACING="0">
  <CAPTION CLASS="TableTitles">Results:</CAPTION>
  <TR>
    <TD WIDTH="20" HEIGHT="20" BACKGROUND="Images/TableUpperLeft.png"></TD>
    <TD WIDTH="260" HEIGHT="20" BACKGROUND="Images/TableUpperMiddle.png"></TD>
    <TD WIDTH="20" HEIGHT="20" BACKGROUND="Images/TableUpperRight.png"></TD>
  </TR>
  <TR>
    <TD WIDTH="20" BACKGROUND="Images/TableMiddleLeft.png"></TD>
	<TD>
	<TABLE WIDTH="260" BORDER="1" BORDERCOLOR="#009900" >
	
    <%
	x=0
	do until x>rcnt
		if set1="nothing" and set2="nothing" then
			entry="<span class='ResultsName'>(No Results Found)</span>"
			link=""
			linkclose=""
		end if
		
		if set1="" and set2="" then
			entry=""
			link=""
			linkclose=""
		end if
		
		if set1="something" or set2="something" then
			entry="<span class='ResultsName'>" & ra3(0,x) & " " & ra3(1,x) & "</span></br>" & "<span class='ResultsAddress'>" & ra3(2,x) & "</span>"
			link="<a href='javascript: OpenAcct(" & chr(34) & ra3(3,x) & chr(34) & ")'>"
			linkclose="<a>"
		end if
	%>	
  	<TR>
    	<TD WIDTH="170" BORDERCOLOR="#FFFFFF" BGCOLOR="#FFFFFF" CLASS="ListCell" onMouseOver="me.bgColor='#D2FFD2'" onMouseOut="me.bgColor='white'"><%= link %><%= entry %>
     	<%= linkclose %>
		</TD>
    </TR>
<%
  		x=x+1
  	loop
%>
	</TABLE>
	</TD>
	<TD WIDTH="20" BACKGROUND="Images/TableMiddleRight.png"></TD>
  </TR>
  <TR>
    <TD WIDTH="20" HEIGHT="20" BACKGROUND="Images/TableLowerLeft.png"></TD>
    <TD WIDTH="260" HEIGHT="20" BACKGROUND="Images/TableLowerMiddle.png"></TD>
    <TD WIDTH="20" HEIGHT="20" BACKGROUND="Images/TableLowerRight.png"></TD>
  </TR>
</TABLE>
 <% 

 %>
</BODY>
</HTML>
